package com.SmartClassroom.system.service.impl;

import com.SmartClassroom.system.common.ErrorCode;
import com.SmartClassroom.system.exception.BusinessException;
import com.SmartClassroom.system.mapper.NotificationMapper;
import com.SmartClassroom.system.model.domain.Notification;
import com.SmartClassroom.system.model.dto.notification.NotificationQueryRequest;
import com.SmartClassroom.system.service.NotificationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * @author baijiayu
 * @description 针对表【Notification】的数据库操作Service实现
 * @createDate 2024-11-19 11:01:52
 */
@Service
public class NotificationServiceImpl extends ServiceImpl<NotificationMapper, Notification> implements NotificationService {

    @Override
    public Page<Notification> getQueryWrapper(Page<Notification> pageParam, NotificationQueryRequest notificationQueryRequest) {
        if (notificationQueryRequest == null) {
            throw new BusinessException(ErrorCode.PARAMS_ERROR, "请求参数为空");
        }
        QueryWrapper<Notification> queryWrapper = new QueryWrapper<>();
        if (notificationQueryRequest.getTitle() != null && notificationQueryRequest.getTitle() != "") {
            queryWrapper.like("title", notificationQueryRequest.getTitle());
        }
        if (notificationQueryRequest.getContent() != null && notificationQueryRequest.getContent() != "") {
            queryWrapper.like("content", notificationQueryRequest.getContent());
        }
        if (notificationQueryRequest.getTimestamp() != null) {
            queryWrapper.like("timestamp", notificationQueryRequest.getTimestamp());
        }
        return this.page(pageParam, queryWrapper);
    }
}




